import { holeStandard } from "./HoleTypeStore";

export class HoleStandard {
  constructor({
      holeType, // 孔类型
      holeTypeValue, // 孔类型对应的内核值
      sizeOptions, // 标准大小列表
      standardOptions, // 标准列表
      showTypes, // 需要显示的类型（独有, 肯定会出现的 mate）
      hidetypes, // 需要隐藏的类型
      labelShowTypes,
      specialShowTypes, // 特有标准包含的显示类型
      specialHideTypes, // 特有标准包含的隐藏类型
    } = {})
  {
    this.holeType = holeType;
    this.holeTypeValue = holeTypeValue;
    this.sizeOptions = sizeOptions;
    this.standardOptions = standardOptions;
    this.showTypes = showTypes;
    this.labelShowTypes = labelShowTypes;
    this.specialShowTypes = specialShowTypes;
    this.specialHideTypes = specialHideTypes;
  }

  getSizeOptions(standardValue, standardType = holeStandard.GB) {
    let options = this.sizeOptions.find(options => options.value === standardValue);
    return options.options.filter(option => option.type === standardType);
  }

  getStandardOptions(standardType= holeStandard.GB) {
    return this.standardOptions.filter(option => option.type === standardType);
  }

  getShowTypes(standardValue) {
    let types = this.showTypes;
    let showList = [];
    showList.push(...types);
    let specialShowTypes = this.specialShowTypes.filter(t => t.value === standardValue);
    if (specialShowTypes.length !== 0) {
      specialShowTypes.forEach(sT => {
        showList.push(sT.type);
      })
    }
    let specialHideTypes = this.specialHideTypes.filter(t => t.value === standardValue);
    if (specialHideTypes.length !== 0) {
      specialHideTypes.forEach(sT => {
        let index = showList.findIndex(s => s === sT.type);
        showList.splice(index, 1);
      })
    }
    return showList;
  }

  getLabelShowTypes() {
    let showLabels = [];
    for (let labelShowTypesKey in this.labelShowTypes) {
      let type = this.labelShowTypes[labelShowTypesKey];
      showLabels.push(type)
    }
    return showLabels;
  }

}



